﻿using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Helloworld.model
{
    class Circle : Polygon
    {
        public float x, y;
        public float radius;
        

        /** Constructs a new circle with all values set to zero */
        public Circle()
        {

        }

        public Circle(float x, float y, float radius)
        {
            
            this.x = x;
            this.y = y;
            this.radius = radius;
        }

        public Circle(Vector2 position, float radius)
        {
            this.x = position.X;
            this.y = position.Y;
            this.radius = radius;
        }

        public Boolean contains(float x, float y)
        {
            x = this.x - x;
            y = this.y - y;
            return x * x + y * y <= radius * radius;
        }

        public Boolean contains(Vector2 point)
        {
            float x = this.x - point.X;
            float y = this.y - point.Y;
            return x * x + y * y <= radius * radius;
        }

        public void set(float x, float y, float radius)
        {
            this.x = x;
            this.y = y;
            this.radius = radius;
        }

        public Boolean overlaps(Circle c)
        {
            float dx = this.x - c.x;
            var dy = this.y - c.y;

            return Math.Sqrt(dx * dx + dy * dy) <= this.radius + c.radius;
        }

        public Boolean overlaps(Rectangle r)
        {
            float px = this.x;
            float py = this.y;
 
            if(px < r.x)
                px = r.x;
            else if(px > r.x+r.width)
                px = r.x + r.width;
 
            if(py < r.y+r.height)
                py = r.y + r.height;
            else if(py > r.y)
                py = r.y;
 
            float dx = this.x - px;
            float dy = this.y - py;
 
            return (dx*dx + dy*dy) <= this.radius*this.radius;

        }
    
    
    }
}
